/*
 * Autor: Alexander Savochkin, 2010
 * New BSD License
 * */

#pragma once
#include <string>
using std::string;

#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/asio.hpp>

#include "IOperatedOutput.h"
#include "Config.h"

using boost::shared_ptr;
using SRCLF::Config::Configuration;

namespace SRCLF
{
namespace IO
{
	/**
	@class PWMOutput
	Represents pulse width modulation. It is wrapper for another IOperatedOutput descendant.
	*/
	class PWMOutput : public IOperatedOutput
	{
		double minimal_value;
		double maximal_value;
		
		double pulses_period;

		double duty_cycle; //between 0 and 1.

		shared_ptr<IOperatedOutput> wrapped_output;
		boost::asio::deadline_timer timer;
		
		short current_state;  //1 or 0
		ptime next_change_time;
	public:
		PWMOutput(const string& name, const Configuration& config);
		virtual ~PWMOutput() {};

		virtual bool open() { wrapped_output->open(); }
		virtual void setOutput( double _value) {   }

		virtual void adminCommand(const string& command, string& result);
		virtual void controlCommand(const string& command, string& result);
		virtual void infoCommand(string& command, string& result);

		virtual void close() { wrapped_output->close(); }
	protected:
		void onTimerAction();
	};

}
}
